#pragma once

#include<iostream>
#include<string>
#include<unistd.h>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;

typedef function<void()> func;

vector<func> callbacks;
unordered_map<int,string> desc;

void readMySQL()
{
    cout<<"process["<< getpid() <<"] 访问数据库任务"<<endl;
}
void execuleUrl()
{
    cout<<"process["<< getpid() <<"] url解析"<<endl;
}
void cal()
{
    cout<<"process["<< getpid() <<"] 加密任务"<<endl;
}
void save()
{
    cout<<"process["<< getpid() <<"] 持久化任务"<<endl;
}

void load()
{
    desc.insert({callbacks.size(),"readMySQL:访问数据库任务"});
    callbacks.push_back(readMySQL);

    desc.insert({callbacks.size(),"execuleUrl:url解析"});
    callbacks.push_back(execuleUrl);

    desc.insert({callbacks.size(),"cal:加密任务"});
    callbacks.push_back(cal);

    desc.insert({callbacks.size(),"save:持久化任务"});
    callbacks.push_back(save);
}

void showHandler()
{
    for(const auto &iter : desc)
    {
        cout<<iter.first<<"\t"<<iter.second<<endl;
    }
}

int handlerSize()
{
    return callbacks.size();
}